#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]) {
    const char *command = NULL;
    
    // 检查是否有参数传入
    if (argc < 2) {
        printf("Usage: %s <1|0>\n", argv[0]);
        printf("  1: 打开设备\n");
        printf("  0: 关闭设备\n");
        return EXIT_FAILURE;
    }
    
    // 根据参数选择执行的命令
    if (strcmp(argv[1], "1") == 0) {
        command = "sudo /home/remote/project/build/test_OpenRefriger_demo";
    } else if (strcmp(argv[1], "0") == 0) {
        command = "sudo /home/remote/project/build/test_CloseRefriger_demo";
    } else {
        printf("无效的参数: %s\n", argv[1]);
        return EXIT_FAILURE;
    }
    
    // 执行命令
    printf("执行命令: %s\n", command);
    int status = system(command);
    
    // 检查执行结果
    if (status == -1) {
        perror("Failed to execute command");
        return EXIT_FAILURE;
    } else if (WIFEXITED(status)) {
        printf("Command exited with status %d\n", WEXITSTATUS(status));
    } else if (WIFSIGNALED(status)) {
        printf("Command terminated by signal %d\n", WTERMSIG(status));
    }
    
    return EXIT_SUCCESS;
}